﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class SelfInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        for (int i = 1950; i <= 2100; i++)
        {
            ListItem lYear = new ListItem();
            lYear.Text = i.ToString();
            year.Items.Add(lYear);
        }

        for (int i = 1926; i <= 1989; i++)
        {
            ListItem BYear = new ListItem();
            BYear.Text = i.ToString();
            BirthYear.Items.Add(BYear);
        }

        for (int i = 1; i <= 12; i++)
        {
            ListItem BMonth = new ListItem();
            BMonth.Text = i.ToString();
            BirthMonth.Items.Add(BMonth);
        }

        for (int i = 1; i <= 31; i++)
        {
            ListItem BDay = new ListItem();
            BDay.Text = i.ToString();
            BirthDay.Items.Add(BDay);
        }
    }
    protected void ExitClick(object sender, EventArgs e)
    {
        Response.Redirect("~/HomePage.aspx", true);
    }

    protected void bt1_Click(object sender , EventArgs e)
    {   
        string name = txtName.Text;
        string  id = txtStuNum.Text;
        string sex = rdlSex.SelectedValue;
        string birth = BirthYear.SelectedValue + "-" + BirthMonth.SelectedValue + "-" + BirthDay.SelectedValue;
        string political = rdlPoliticalStatus.SelectedValue;
        string marry = rdlMaritalStatus.SelectedValue;
        string health = rdlHlthCond.SelectedValue;
        string major = ddlMajor.SelectedValue;
        string edu = txtSchoolSystem.Text;
        string train = rdlTrainClass.SelectedValue;
        string gratime = year.SelectedValue + "-06-07";
        string move = txtDomicilePlace.Text;
        string mobile = txtPhoneNum.Text;
        string qq = txtQQ.Text;
        string home = txtHomeAdd.Text;
        string msn = txtMSN.Text;
        string email = txtEmail.Text;

        string conStr = @"Data Source=ADMIN-PC\SQLEXPRESS;Initial Catalog=graduate_manage;Integrated Security=True";

        SqlConnection connection = new SqlConnection(conStr);
        SqlCommand cmd = connection.CreateCommand();
        
        cmd.Parameters.Add("@name", SqlDbType.NVarChar, 20).Value = name;
        cmd.Parameters.Add("@id", SqlDbType.VarChar, 20).Value = id;
        cmd.Parameters.Add("@sex", SqlDbType.NVarChar, 20).Value = sex;
        cmd.Parameters.Add("@birth", SqlDbType.Date).Value = birth;
        cmd.Parameters.Add("@political", SqlDbType.NVarChar, 50).Value = political;
        cmd.Parameters.Add("@marry", SqlDbType.NVarChar, 10).Value = marry;
        cmd.Parameters.Add("@health", SqlDbType.NVarChar, 50).Value = health;
        cmd.Parameters.Add("@major", SqlDbType.NVarChar, 100).Value = major;
        cmd.Parameters.Add("@edu", SqlDbType.NVarChar, 50).Value = edu;
        cmd.Parameters.Add("@train", SqlDbType.NVarChar, 50).Value = train;
        cmd.Parameters.Add("@gratime", SqlDbType.Date).Value = gratime;
        cmd.Parameters.Add("@move", SqlDbType.NVarChar, 200).Value = move;
        cmd.Parameters.Add("@mobile ", SqlDbType.VarChar, 20).Value = mobile;
        cmd.Parameters.Add("@qq", SqlDbType.VarChar, 20).Value = qq;
        cmd.Parameters.Add("@home", SqlDbType.NVarChar, 200).Value = home;
        cmd.Parameters.Add("@msn", SqlDbType.NVarChar, 50).Value = msn;
        cmd.Parameters.Add("@email", SqlDbType.NVarChar, 50).Value =email;

        using (connection)
        {
            connection.Open();
              cmd.CommandText = "UPDATE INFO_GRADUATE SET "
              + "GRA_NAME = @name,GRA_ID=@id,GRA_SEX=@sex,GRA_BIRTH=@birth,GRA_POLITICAL=@political,"
              + "GRA_MARRY=@marry,GRA_HEALTH=@health,GRA_MAJOR=@major,GRA_EDUCATION=@edu,GRA_TRAIN=@train,GRA_GRATIME=@gratime,GRA_MOVE=@move," +
              "GRA_MOBILE=@mobile,GRA_QQ=@qq,GRA_HOME=@home,GRA_MSN=@msn,GRA_EMAIL=@email WHERE GRA_ID=@id";
             string TEXT = cmd.CommandText;
                Response.Write(TEXT);
              cmd.ExecuteNonQuery();

        }
    }

   
}

   
